<template>
  <div class="lang">
    <el-dropdown @command="command">
      <span class="el-dropdown-link">
        <i class="el-icon-eleme"></i>
      </span>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item command="zh" :disabled="local === 'zh'"
          >中文</el-dropdown-item
        >
        <el-dropdown-item command="en" :disabled="local === 'en'"
          >English</el-dropdown-item
        >
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</template>

<script>
import Cookie from 'js-cookie'
export default {
  name: 'mylang',
  data () {
    return {
      local: Cookie.get('lang') || 'zh'
    }
  },
  methods: {
    command (name) {
      if (name === 'zh') {
        // 改为英文
        Cookie.set('lang', 'zh')
      } else {
        // 改为中文
        Cookie.set('lang', 'en')
      }
      window.location.reload()
    }
  }
}
</script>

<style lang="scss">
.lang {
  margin-right: 10px;
  .el-dropdown-link {
    color: #fff;
  }
}
</style>
